function populatePage() {
  var order = document.location.search.substr(1);
  order = order.replace(/%20/g," ").split('+');

  for(var i=0; i<order.length; i++) {
    order[i] = order[i].split('&');
  }

  if(order[0][0] == "deliver") { 
    var delivery = order.shift();
    delivery.shift();
    
    var preElement = document.getElementById("delivery-information");
    var text = "Delivery on "+delivery[0]+"\r\n"; // Date
    text += "Address: \r\n";
    text += delivery[1]+"\r\n";    // Name
    text += delivery[2]+"\r\n";    // Street
    text += delivery[3]+" "+delivery[4]+", "+delivery[5]+"\r\n";    // City State, Zip
    
    preElement.firstChild.nodeValue = text;
  }

  var table = document.getElementById("order-table");
  table.removeChild(table.firstChild); // I included a dummy row to validate order.html as XHTML strict
  var totalPrice = 0;
  for(i=0; i<order.length; i++) {
    var row = document.createElement("tr");
    
    var sandwich = document.createElement("td");
    sandwich.appendChild(document.createTextNode(order[i][0]));
    row.appendChild(sandwich);
    
    var quantity = document.createElement("td");
    quantity.appendChild(document.createTextNode(order[i][1]));
    row.appendChild(quantity);
    
    var price = document.createElement("td");
    price.appendChild(document.createTextNode("$"+order[i][2]));
    row.appendChild(price);
    totalPrice += order[i][2]*1;
    
    table.appendChild(row);
  }
  var priceRow = document.createElement("tr");
  var label = document.createElement("th");
  label.colSpan = "2";
  label.appendChild(document.createTextNode("Total Price"));
  priceRow.appendChild(label);
  var value = document.createElement("td");
  value.appendChild(document.createTextNode("$"+totalPrice.toFixed(2)));
  priceRow.appendChild(value);
  table.appendChild(priceRow);
}

window.onload = populatePage;
